import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;


public class BaseMenu extends Menu {
	private boolean visible;
	private int size;
	private int turnNum;
	ArrayList<Player> players;
	SOCApplet applet;
	
	private MenuButton dieButton;
	private MenuButton tradeButton;
	private MenuButton buildButton;
	private MenuButton endButton;
	
	
	private BufferedImage bottom_panel;
	private BufferedImage face_pic;
	
	
	public BaseMenu(int size, ArrayList<Player> players, ArrayList<Menu> menus, SOCApplet applet){
		turnNum = 0;
		
		//the four menu buttons with name, coordinates and the menu they will activate
		dieButton = new MenuButton("dieButton", 98, 606, 30, 34, menus.get(0));
		tradeButton = new MenuButton("tradeButton", 142, 606, 30, 34, menus.get(1));
		buildButton = new MenuButton("buildButton", 142, 643, 30, 34, menus.get(2));
		endButton = new MenuButton("endButton", 98, 643, 30, 34, new TurnMenu(applet));
		
		
		//base menu is always visible
		visible = true;
		
		//sets up images
		try {
			bottom_panel = ImageIO.read(new File("bottom_panel.jpg"));
			face_pic = ImageIO.read(new File("smiley.jpg"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		this.size = size;
		this.players = players;
		this.applet = applet;
	}
	
	//checks for overlaps on all buttons
	public void checkOverlaps(int x, int y){
		if (!applet.getTurn().isDiceRolled()){
			dieButton.overlaps(x, y);
		} else {
			tradeButton.overlaps(x, y);
			buildButton.overlaps(x, y);
			endButton.overlaps(x, y);
		}
	}
	
	public void updateTurn(){
		turnNum ++;
		turnNum = turnNum % 4;
	}
	
	//draws self and updates info for stats from players.
	public void drawSelf(Graphics g){
		int vPts = ((Player)applet.getTurn().getPlayer()).getvPts();
		int roadNum = ((Player)applet.getTurn().getPlayer()).roadNum;
		int armyNum = ((Player)applet.getTurn().getPlayer()).getArmyNum();
		int specialCards = ((Player)applet.getTurn().getPlayer()).getHand().getCards().size();
		int specialVPts = ((Player)applet.getTurn().getPlayer()).getSpecialVPts();
		int rCardsNum = ((Player)applet.getTurn().getPlayer()).getBrick() + 
						((Player)applet.getTurn().getPlayer()).getGrain() + 
						((Player)applet.getTurn().getPlayer()).getLumber() + 
						((Player)applet.getTurn().getPlayer()).getOre() + 
						((Player)applet.getTurn().getPlayer()).getWool();
		
		g.drawImage(bottom_panel, 0, size * 14 - 118, null);
		g.drawImage(face_pic, 30, size * 14 - 75, null);
		g.drawString(vPts + "", 210, size * 14 - 25);
		g.drawString(roadNum + "", 245, size * 14 - 25);
		g.drawString(armyNum + "", 280, size * 14 - 25);
		g.drawString(specialCards + "", 315, size * 14 - 25);
		g.drawString(specialVPts + "", 350, size * 14 - 25);
		g.drawString(rCardsNum + "", 385, size * 14 - 25);
	}
	
	//no activate for baseMenu. always visible
	public void activate(String buttonName) {
	}
}
